/*****************************************************************************
 *  CommLayerLib for Android - StreamLogger.java
 *  Copyright (C) 2012  Matteo Piscitelli
 *  E-mail: matteo@picciux.it
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  For further info, check http://code.google.com/p/java-comm-layer/
 *
 *  SVN: $Id: StreamLogger.java 45 2012-10-11 16:48:14Z picciux@gmail.com $
 *  
 *****************************************************************************/

package it.picciux.commlayer.android.log;

import java.io.OutputStream;
import java.util.logging.SimpleFormatter;
import java.util.logging.StreamHandler;

public class StreamLogger extends Logger {

	public StreamLogger(String moduleName) {
		super(moduleName);
		setupLogger();
	}
	
	public StreamLogger(String moduleName, OutputStream outputStream) {
		super(moduleName);
		setupLogger();
		setOutputStream(outputStream);
	}

	public void setOutputStream(OutputStream outputStream) {
		if (handler != null) return;
		handler = new StreamHandler(outputStream, new SimpleFormatter());
		logger.addHandler(handler);
		handler.setLevel(getLevelObject(getLevel()));				
	}
	
	private void setupLogger() {
		logger = java.util.logging.Logger.getLogger(modName);
		logger.setUseParentHandlers(false);
		logger.setLevel(getLevelObject(getLevel()));		
	}
}
